import { _decorator, AudioSource, BlockInputEvents, Button, Component, director, EventHandler, find, game, instantiate, JsonAsset, Label, log, Node, Prefab, resources, size, Sprite, SpriteAtlas, SpriteFrame, tween, UIOpacity, UITransform, v2, v3, Vec2, Vec3 } from 'cc';
import Banner from './Banner';
import { BundleManager } from './BundleManager';
import { AudioManager } from './AudioManager';
import { LoadingPanel } from './UI/LoadingPanel';
import { PoolManager } from './PoolManager';

const { ccclass, property } = _decorator;

@ccclass('UIManager')
export class UIManager extends Component {


    public GameScene: number = 0;

    private static _instance: UIManager = null;
    public static get Instance() {
        if (!this._instance) {
            this._instance = new UIManager();
        }
        return this._instance;
    }
    protected onLoad(): void {
        UIManager._instance = this;
        AudioManager.AudioSource = this.node.getComponent(AudioSource);
    }
    start() {

    }




    //弹出提示
    public static HopHint(str: string, time: number = 1, pos: Vec3 = v3(0, 0, 0), pianyi: Vec3 = v3(0, 120, 0)) {
        PoolManager.GetNode("Prefab/提示", UIManager.Instance.node.getChildByName("Canvas"), pos).then((pre: Node) => {
            pre.active = true;
            pre.getChildByName("内容").getComponent(Label).string = str;
            pre.getChildByName("内容").getComponent(Label).updateRenderData(true);
            pre.getChildByName("对话框").getComponent(UITransform).width = pre.getChildByName("内容").getComponent(UITransform).width + 40;
            tween(pre)
                .by(time, { position: pianyi })
                .call(() => {
                    pre.active = false;
                    PoolManager.PutNode(pre)
                })
                .start();
        });




    }

    //前往场景
    public static GoScene(name: string) {
        UIManager.Instance.node.getChildByPath("Canvas/加载背景").active = true;
        UIManager.Instance.node.getChildByPath("Canvas/加载背景").getComponent(LoadingPanel).Show(name);
    }

}

